package com.egao.oa.controller;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.oa.entity.GzhMessage;
import com.egao.oa.service.GzhMessageService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 *
 * 公告
 * @author : Doman
 * @date : 2021-01-22 15:17:17
 * @version ：1.0
 */

@Controller
@RequestMapping("/oa/gzhMessageNt")
public class NtGzhMessageController extends BaseController {

	@Autowired
	private GzhMessageService gzhMessageService;

    /**
     * 页面
     **/
    @RequestMapping()
    public String cPage() {
        return "oa/cGzhMessage.html";
    }


    /**
	 * 分页查询列表
	 */
//	@RequiresPermissions("oa:gzhMessage:list")
	@ResponseBody
	@RequestMapping("/page")
    public JsonResult list(PageResult2<T> page, GzhMessage gzhMessage) throws Exception{
        return gzhMessageService.list(page, gzhMessage, getLoginUser());
    }

    /**
     * 查询全部公告
     */
//    @RequiresPermissions("oa:gzhMessage:list")
    @ResponseBody
    @RequestMapping("/list")
    public JsonResult list(GzhMessage gzhMessage){
        return JsonResult.ok().setData(gzhMessageService.list(gzhMessage, getLoginUser()));
    }

    /**
     * 根据id查询公告
     */
//    @RequiresPermissions("oa:gzhMessage:list")
    @ResponseBody
    @RequestMapping("/get")
    public JsonResult get(GzhMessage gzhMessage) {
        return gzhMessageService.getById(gzhMessage);
		// 使用关联查询
        //PageParam<gzhMessage> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<gzhMessage> records = gzhMessageService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }

    /**
     * 根据id查询公告
     */
//    @RequiresPermissions("oa:gzhMessage:list")
    @ResponseBody
    @RequestMapping("/getLast")
    public JsonResult getLast(GzhMessage gzhMessage) {
        return gzhMessageService.getLast(gzhMessage);
		// 使用关联查询
        //PageParam<gzhMessage> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<gzhMessage> records = gzhMessageService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加公告
     */
//    @RequiresPermissions("oa:gzhMessage:save")
    @OperLog(value = "公告", desc = "添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/save")
    public JsonResult save(Model model, GzhMessage gzhMessage) {
        return gzhMessageService.save(gzhMessage, getLoginUser());
    }

    /**
     * 修改公告
     */
//    @RequiresPermissions("oa:gzhMessage:update")
    @OperLog(value = "公告", desc = "修改", param = false, result = true)
    @ResponseBody
    @RequestMapping("/update")
    public JsonResult update(Model model, GzhMessage gzhMessage) {
        return gzhMessageService.update(gzhMessage, getLoginUser());
    }

    /**
     * 删除公告
     */
//    @RequiresPermissions("oa:gzhMessage:remove")
    @OperLog(value = "公告", desc = "删除", result = true)
    @ResponseBody
    @RequestMapping("/remove")
    public JsonResult remove(GzhMessage gzhMessage ) {
        return gzhMessageService.remove(gzhMessage, getLoginUser());
    }

    /**
     * 批量添加公告
     */
    /**@RequiresPermissions("oa:gzhMessage:save")
    @OperLog(value = "公告", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<GzhMessage> list) {
        if (gzhMessageService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改公告
     */
    /**@RequiresPermissions("oa:gzhMessage:update")
    @OperLog(value = "公告", desc = "批量修改", result = true)
    @ResponseBody
    @RequestMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<GzhMessage> batchParam) {
        if (batchParam.update(gzhMessageService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除公告
     */
    /**@RequiresPermissions("oa:gzhMessage:remove")
    @OperLog(value = "公告", desc = "批量删除", result = true)
    @ResponseBody
    @RequestMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (gzhMessageService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
